package com.kitchen.ui.controls
{
	import com.kitchen.model.Vo.AccountVo;
	import com.kitchen.ui.controls.stock.StockButton;
	import com.kitchen.ui.controls.stock.StockCarIcon;
	import com.kitchen.ui.controls.stock.StockLoad;
	
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	public class StockBar extends Sprite
	{
		public var h:Number;
		public var w:Number;
		private var mainSkin:BitmapData;
		private var shoper:Object;
		private var shop:Object;
		private var load:StockLoad;
		private var car:StockCarIcon;
		//fortest
		private var rate:Number;
		
		public function StockBar(mainSkin:BitmapData, shoper:Object, shop:Object)
		{
			super();
			this.mainSkin = mainSkin;
			this.shop = shop;
			this.shoper = shoper;
			this.w = 220;
			this.h = 70;
			this.rate = 0;
			this.layout();
		}
		
		private function layout():void{
			this.load = new StockLoad(this.mainSkin);
			this.load.y = 38;
			this.addChild(this.load);
			this.car = new StockCarIcon(this.mainSkin);
			this.addChild(this.car);
			var stock:StockButton = new StockButton(this.mainSkin);
			stock.y = 38;
			stock.x = 162;
			stock.addEventListener(MouseEvent.CLICK, clickHandle);
			this.addChild(stock);
		}
		
		private function clickHandle(me:MouseEvent):void{
			if(this.rate < 1){
				this.rate += 0.1;
			}else{
				this.rate = 0;
			}
			this.rate = this.rate>1?1:this.rate;
			this.car.x = Math.ceil((this.load.w - this.car.w)*this.rate);
			this.load.setLoadedRate(this.rate);
		}
		
	}
}